<template>
  <div class="vehicle-right">
    <div class="vehicle-box">
      <span v-for="(item, index) in vehicleModels"
            :key="index"
            :class="activeClassValue(item) ? 'active' : 'cancel'"
            @click="handerVehModel(item, index)">
        <img class="vehicle-img"
             :src="item.image"
             alt="">
        <div class="text">{{ item.name }}</div>
        <span v-if="activeClassValue(item) "
              class="iconClass">
          <img src="@/static/images/xuanzhong.png">
        </span>
      </span>
    </div>
    <div v-if="disabled"
         class="mask">
    </div>
  </div>
</template>

<script>
import vehicleModels, { loadVehicleModels } from "@basic/assets/vehicle.models";

const format = {
  key: "value",
  label: "name"
}

export default {
  name: 'VehicleSelect',
  props: {
    value: {
      type: Object,
      default: () => { }
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      activeIndex: null
    }
  },
  computed: {
    vehicleModels () {
      return vehicleModels.value;
    },
    activeClassValue () {
      return item => item[format.key] === this.value?.value
    }
  },
  created () {
    loadVehicleModels()
  },
  methods: {
    handerVehModel (item) {
      this.$emit('input', item)
    }
  }
}
</script>

<style scoped>
.vehicle-right {
  position: relative;
}
.vehicle-box {
  /* display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between; */
  display: grid;
  justify-content: space-between;
  grid-template-columns: repeat(auto-fill, 80px);
  grid-gap: 0 1px;
}
/* .vehicle-box::after {
  content: "";
  width: 90px;
} */
.vehicle-box span {
  width: 70px;
  height: 70px;
  line-height: 70px;
  text-align: center;
  line-height: 20px;
  cursor: pointer;
  margin-bottom: 8px;
  position: relative;
}
.text {
  font-size: 12px;
  /* color: #666; */
}
.active {
  border: 1px solid var(--prev-color-primary);
  color: var(--prev-color-primary);
  border-radius: 2px;
}
.cancel {
  border: 1px solid #eee;
  color: #666;
  border-radius: 2px;
}
.vehicle-img {
  width: 70px;
}
.iconClass img {
  width: 15px;
  height: 15px;
}
.iconClass {
  position: absolute;
  bottom: 9px;
  right: -28px;
}
.mask {
  width: 100%;
  height: 240px;
  position: absolute;
  top: 0;
  background-color: var(--prev-bg-color);
  border-color: #e4e7ed;
  color: #c0c4cc;
  cursor: not-allowed;
  opacity: 0.4;
}
</style>